//
//  ViewController.m
//  Masonry例子
//
//  Created by 楼楚 on 16/3/24.
//  Copyright © 2016年 Chu Lou. All rights reserved.
//

#import "ViewController.h"
#import "Masonry.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self initSubViews];
}

-(void)initSubViews
{
//    创建子视图，并添加到父视图
    
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.backgroundColor = [[UIColor redColor]colorWithAlphaComponent:0.5f];
    [self.view addSubview:button1];
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    button2.backgroundColor = [[UIColor greenColor]colorWithAlphaComponent:0.5f];
    [self.view addSubview:button2];

    
    UIButton *button3 = [UIButton buttonWithType:UIButtonTypeCustom];
    button3.backgroundColor = [[UIColor blueColor]colorWithAlphaComponent:0.5f];
    [self.view addSubview:button3];

    
    UIButton *button4 = [UIButton buttonWithType:UIButtonTypeCustom];
    button4.backgroundColor = [[UIColor orangeColor]colorWithAlphaComponent:0.5f];
    [self.view addSubview:button4];

    
    
    UIButton *button5 = [UIButton buttonWithType:UIButtonTypeCustom];
    button5.backgroundColor = [[UIColor yellowColor]colorWithAlphaComponent:0.5f];
    [self.view addSubview:button5];

    
    UIButton *button6 = [UIButton buttonWithType:UIButtonTypeCustom];
    button6.backgroundColor = [[UIColor purpleColor]colorWithAlphaComponent:0.5f];
    [self.view addSubview:button6];
//    添加约束
    [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
//     上边距离父视图上边3个单位
        make.top.equalTo(self.view.mas_top).with.offset(3);
//        坐边距离父视图左边3个单位
        make.left.equalTo(self.view.mas_left).with.offset(3);
//        宽度是父视图宽度的一半
        make.width.equalTo(self.view.mas_width).with.multipliedBy(0.5);
//        高度是父视图高度的0.2倍
        make.height.equalTo(self.view.mas_height).with.multipliedBy(0.2);
    }];
    
   [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(self.view.mas_top).with.offset(3);
//       右边距离父视图右边3个单位，-3表示在父视图内，如果是+3的话会跑出父视图外
       make.right.equalTo(self.view.mas_right).with.offset(-3);
//       左边距离button1的右边3个单位
        make.left.equalTo(button1.mas_right).with.offset(3);
       make.height.equalTo(self.view.mas_height).with.multipliedBy(0.2);
          }];
    [button3 mas_makeConstraints:^(MASConstraintMaker *make) {
//      上边距离button1的下边3个单位
        make.top.equalTo(button1.mas_bottom).with.offset(3);
        make.left.equalTo(self.view.mas_left).with.offset(3);
//     宽度与button1等宽
        make.width.equalTo(button1.mas_width);
//    高度与button1等高
        make.height.equalTo(button1.mas_height);
    }];
    
    [button4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(button2.mas_bottom).with.offset(3);
       
        make.right.equalTo(self.view.mas_right).with.offset(-3);
    
        make.left.equalTo(button3.mas_right).with.offset(3);
         make.height.equalTo(button3.mas_height);
    }];
    
    [button5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(button3.mas_bottom).with.offset(3);
        make.left.equalTo(self.view.mas_left).with.offset(3);
        make.width.equalTo(button1.mas_width);
        make.height.equalTo(button1.mas_height);
        
    }];
    [button6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(button4.mas_bottom).with.offset(3);
        
        make.right.equalTo(self.view.mas_right).with.offset(-3);
        
        make.left.equalTo(button5.mas_right).with.offset(3);
        make.height.equalTo(button5.mas_height);
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
